package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompWorkOrder;
import com.ruoyi.womp.service.IWompWorkOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单列表Controller
 * 
 * @author mzz
 * @date 2022-04-11
 */
@Controller
@RequestMapping("/womp/workOrder")
public class WompWorkOrderController extends BaseController
{
    private String prefix = "womp/workOrder";

    @Autowired
    private IWompWorkOrderService wompWorkOrderService;

    @RequiresPermissions("womp:workOrder:view")
    @GetMapping()
    public String workOrder()
    {
        return prefix + "/workOrder";
    }

    /**
     * 查询工单列表列表
     */
    @RequiresPermissions("womp:workOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompWorkOrder wompWorkOrder)
    {
        startPage();
        List<WompWorkOrder> list = wompWorkOrderService.selectWompWorkOrderList(wompWorkOrder);
        return getDataTable(list);
    }

    /**
     * 导出工单列表列表
     */
    @RequiresPermissions("womp:workOrder:export")
    @Log(title = "工单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompWorkOrder wompWorkOrder)
    {
        List<WompWorkOrder> list = wompWorkOrderService.selectWompWorkOrderList(wompWorkOrder);
        ExcelUtil<WompWorkOrder> util = new ExcelUtil<WompWorkOrder>(WompWorkOrder.class);
        return util.exportExcel(list, "工单列表数据");
    }

    /**
     * 新增工单列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工单列表
     */
    @RequiresPermissions("womp:workOrder:add")
    @Log(title = "工单列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompWorkOrder wompWorkOrder)
    {
        return toAjax(wompWorkOrderService.insertWompWorkOrder(wompWorkOrder));
    }

    /**
     * 修改工单列表
     */
    @RequiresPermissions("womp:workOrder:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WompWorkOrder wompWorkOrder = wompWorkOrderService.selectWompWorkOrderById(id);
        mmap.put("wompWorkOrder", wompWorkOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存工单列表
     */
    @RequiresPermissions("womp:workOrder:edit")
    @Log(title = "工单列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompWorkOrder wompWorkOrder)
    {
        return toAjax(wompWorkOrderService.updateWompWorkOrder(wompWorkOrder));
    }

    /**
     * 删除工单列表
     */
    @RequiresPermissions("womp:workOrder:remove")
    @Log(title = "工单列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompWorkOrderService.deleteWompWorkOrderByIds(ids));
    }
}
